package com.yunxin.core.infra.persistence.repository.merchant;

import com.yunxin.core.domain.model.merchant.MerchantInvoiceInfo;
import com.yunxin.core.domain.model.merchant.MerchantInvoiceInfoRepository;
import com.yunxin.core.infra.persistence.converter.MerchantConverter;
import com.yunxin.core.infra.persistence.entity.merchant.MerchantInvoiceInfoDO;
import com.yunxin.core.infra.persistence.mapper.merchant.MerchantInvoiceInfoExtendMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

/**
 * @author zero°
 * @since 2023-07-12
 */
@Repository
@RequiredArgsConstructor
public class MerchantInvoiceInfoRepositoryImpl implements MerchantInvoiceInfoRepository {

    private final MerchantInvoiceInfoExtendMapper merchantInvoiceInfoExtendMapper;

    private final MerchantConverter merchantConverter;

    @Override
    public boolean saveMerchantContactPerson(MerchantInvoiceInfo merchantInvoiceInfo) {
        MerchantInvoiceInfoDO merchantInvoiceInfoDO = merchantConverter.formMerchantInvoiceInfo(merchantInvoiceInfo);
        int count = merchantInvoiceInfoExtendMapper.insertSelective(merchantInvoiceInfoDO);
        return count > 0;
    }

    @Override
    public boolean updateMerchantContactPerson(MerchantInvoiceInfo merchantInvoiceInfo) {
        MerchantInvoiceInfoDO merchantInvoiceInfoDO = merchantConverter.formMerchantInvoiceInfo(merchantInvoiceInfo);
        int count = merchantInvoiceInfoExtendMapper.updateByPrimaryKeySelective(merchantInvoiceInfoDO);
        return count > 0;
    }

    @Override
    public boolean updateMerchantInvoiceInfoDelPersonByMerchantId(String editor, Long merchantId) {
        int count = merchantInvoiceInfoExtendMapper.updateMerchantInvoiceInfoDelPersonByMerchantId(editor,merchantId );
        return count > 0;
    }
}
